package com.example.imtoken.modules.main.wallet.manage.wallet.add

import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.LogUtils
import com.example.imtoken.core.base.BaseViewModel
import com.example.imtoken.core.http.BaseObserver
import com.example.imtoken.core.logic.network.RetrofitUtils
import com.example.imtoken.entitys.http.CoinsEntity
import com.example.imtoken.entitys.http.CoinsEntityItem
import com.example.imtoken.entitys.http.ResponseEntity
import io.reactivex.schedulers.Schedulers

class AddWalletViewModel : BaseViewModel() {

    private val coinsLiveData = MutableLiveData<MutableList<CoinsEntityItem>>()
    fun getCoinsLiveData(): MutableLiveData<MutableList<CoinsEntityItem>> {
        return coinsLiveData
    }

    fun getCoinsData() {
        RetrofitUtils.apiService?.coins()
            ?.subscribeOn(Schedulers.io())
            ?.unsubscribeOn(Schedulers.io())
            ?.subscribe(object : BaseObserver<ResponseEntity<CoinsEntity>>() {
                override fun onSuccess(value: ResponseEntity<CoinsEntity>) {
                    if (value.code == 0) {
                        coinsLiveData.postValue(value.data)
                    } else {
                        mErrorStr.postValue(value.msg)
                    }
                }

                override fun onFailed(e: Throwable) {
                    LogUtils.e(e.message)
                }

            })
    }

}